﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace domen
{
    public static class SorterHelper
    {
        public static IEnumerable<string> SelectStartEndEqual(this IEnumerable<string> strings)
        {
            return strings.Distinct().Where(s => (s[0] == s[s.Length - 1]));
        }

        public static IEnumerable<string> SelectStartEndEqualTwo(this IEnumerable<string> strings)
        {
            return strings.Distinct().Where(s => (s[0] == s[s.Length - 1]))
                .Where(s => (s[1] == s[s.Length - 2]));

        }


        public static IEnumerable<string> SelectDistinct(this IEnumerable<string> strings)
        {
            return strings.Distinct().Where(s =>s.Length == s.Distinct().Count());
        }


        public static IEnumerable<string> SortByLength(this IEnumerable<string> strings)
        {
            return strings.OrderBy(s => s.Length).Distinct().OrderBy(s => s.Length);
        }

        public static IEnumerable<string> SortByAbc(this IEnumerable<string> strings)
        {
            return strings.OrderBy(s => s.Length).Distinct().OrderBy(s => s);
        }

        public static IEnumerable<string> SortByLenghtAndABC(this IEnumerable<string> strings)
        {
            var result = new List<string>();
            var s2 = strings.Where(s => (s.Length == 2)).Distinct().OrderBy(s => s);
            var s3 = strings.Where(s => (s.Length == 3)).Distinct().OrderBy(s => s);
            var s4 = strings.Where(s => (s.Length == 4)).Distinct().OrderBy(s => s);
            var s5 = strings.Where(s => (s.Length == 5)).Distinct().OrderBy(s => s);
            var s6 = strings.Where(s => (s.Length == 6)).Distinct().OrderBy(s => s);
            var s7 = strings.Where(s => (s.Length == 7)).Distinct().OrderBy(s => s);
            var sOther = strings.Where(s => (s.Length >= 8)).OrderBy(s => s);
            result.AddRange(s2);
            result.AddRange(s3);
            result.AddRange(s4);
            result.AddRange(s5);
            result.AddRange(s6);
            result.AddRange(s7);
            result.AddRange(sOther);
            return result;
        }
    }
}
